package repository

import (
	"log"
	"palms/model"
	"xorm.io/xorm"
)

type RobotRepository interface {
	List(pageNo int, pageSize int) []model.Robot

	Get(id int64) model.Robot

	Delete(id int64)

	Insert(robot model.Robot) error

	MatchAll(tags []string) ([]model.Robot, error)
}

func NewRobotRepository(engine *xorm.Engine) RobotRepository {
	return &robotRepository{
		engine: engine,
	}
}

type robotRepository struct {
	engine *xorm.Engine
}

func (r *robotRepository) MatchAll(tags []string) ([]model.Robot, error) {
	var robots = make([]model.Robot, 0)
	err := r.engine.Where("tag @> ?", tags).Find(robots)
	if err != nil {
		log.Printf("查询匹配标签的机器人列表失败[tags:%s]\n", tags)
		return nil, err
	}
	return robots, nil
}

func (r *robotRepository) List(pageNo int, pageSize int) []model.Robot {
	return []model.Robot{}
}

func (r *robotRepository) Get(id int64) model.Robot {
	return model.Robot{}
}

func (r *robotRepository) Delete(id int64) {
}

func (r *robotRepository) Insert(robot model.Robot) error {
	return nil
}
